Skip to content

Let's twist again! - #612

Merged
lkdvos merged 4 commits into
mainfrom
contract-fuse
Nov 22, 2026
Merged

lkdvos merged 4 commits into
mainfrom
contract-fuse

Conversation

@lkdvos

@lkdvos lkdvos commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

For fermionic sectors, blas_contract! twists the contracted legs of one of the operands. That operand is always copied first, so this PR folds the twist into the recoupling coefficients of the copy, instead of running a separate twist! pass over it (#595).

  • treebraider takes a twistmask on the destination legs. Twists are diagonal in the fusion tree basis, so they are multiplied into the braiding coefficients. Ordinary braids and permutations pass an all-false mask and are unchanged, so no extra transformer type or cache is needed. _braid! and its GPU and diagonal-GPU counterparts gain the same argument.
  • blas_contract! computes both twist masks in contraction_twistmasks and always copies through permute_twist!, passing an all-false mask when no twist is needed.

On a fℤ₂×U(1) operand with 1336 subblocks, the twisted copy goes from 0.80 ms to 0.40 ms.

This also fixes the GPU "Adapt SectorVector" test from #610: for IsingBimodule, V1 ⊗ V2 ← V3 has incompatible units and threw a SpaceMismatch, so it now reuses the space of the "Adapt" testset.

Tested locally on Julia 1.13: the contraction, index manipulation, diagonal, braiding tensor and planar suites, the CUDA tensor suite and the Mooncake contraction tests pass. Enzyme was not run locally.

🤖 Generated with Claude Code

@lkdvos
lkdvos marked this pull request as ready for review November 5, 2026 16:18
@kshyatt

kshyatt commented Nov 12, 2026

Copy link
Copy Markdown
Member

This also fixes the GPU "Adapt SectorVector" test from #610: for IsingBimodule, V1 ⊗ V2 ← V3 has incompatible units and threw a SpaceMismatch, so it now reuses the space of the "Adapt" testset.

I think this already got fixed, right?

@Jutho

Jutho commented Nov 19, 2026

Copy link
Copy Markdown
Member

My first and probably most pertinent comment is that this PR's title should clearly have been: "let's twist again".

@lkdvos lkdvos changed the title Fold the twist of fermionic contraction operands into their permutation Let's twist again! Nov 20, 2026
Comment thread src/tensors/tensoroperations.jl Resolved
@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
ext/TensorKitGPUArraysExt.jl 96.96% <100.00%> (ø)
src/tensors/indexmanipulations.jl 91.53% <100.00%> (+0.03%) ⬆️
src/tensors/tensoroperations.jl 97.35% <100.00%> (+0.01%) ⬆️
src/tensors/treetransformers.jl 96.85% <100.00%> (+0.14%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The operand that `blas_contract!` twists for fermionic sectors is always copied first, so the
twist is now folded into the recoupling coefficients of that copy through a cached
`treepermuter`, instead of a separate `twist!` pass over the copied operand (#595).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lkdvos and others added 3 commits November 22, 2026 12:27
…epermuter`

`blas_contract!` now computes the twist masks of both operands in `contraction_twistmasks`
and always copies through `permute_twist!`, with an all-false mask when no twist is needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
The GPU method still had the old six-argument signature, so the new
seven-argument call from `_braid!` fell back to the host `treebraider` and
built a host transformer for GPU storage, which `add_transform_kernel!`
in the GPU extension does not accept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lkdvos

lkdvos commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Should be ready for merging now!

@lkdvos
lkdvos merged commit 590ccc1 into main Nov 22, 2026
16 of 19 checks passed
@lkdvos
lkdvos deleted the contract-fuse branch November 22, 2026 18:56
@Jutho

Jutho commented Nov 23, 2026

Copy link
Copy Markdown
Member

What was still missing/wrong?

@lkdvos

lkdvos commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

630 was merged first, that was all, so I just fixed the small merge conflict for the deduplication step

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants